package com.yuncool.sky.system.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuncool.sky.system.domain.SysParam;
import com.yuncool.sky.system.mapper.SysParamMapper;
import com.yuncool.sky.system.pojo.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Auther XIE
 * @Date 2019/11/22 22:17
 * @Description 系统参数服务类
 * @Version 1.0
 */
@Service
public class SysParamService extends ServiceImpl<SysParamMapper, SysParam> {

    @Autowired
    private SysParamMapper sysParamMapper;

    /**
     * 获取后台管理员
     *
     * @return
     */
    public SysUser getSystemUser() {
        SysParam userNameParam = sysParamMapper.selectOne(
                new QueryWrapper<SysParam>()
                        .lambda()
                        .eq(SysParam::getParamName, "SYSTEM_ADMIN_NUMBER"));
        SysParam passwordParam = sysParamMapper.selectOne(
                new QueryWrapper<SysParam>()
                        .lambda()
                        .eq(SysParam::getParamName, "SYSTEM_ADMIN_PASSWORD"));
        return new SysUser(userNameParam.getParamValue(), passwordParam.getParamValue());
    }

    /**
     * 获得抢课结束时间
     *
     * @return
     */
    public String getEndTime() {
        return sysParamMapper.selectOne(new QueryWrapper<SysParam>().lambda().eq(SysParam::getParamName, "SELECT_COURSE_END_TIME")).getParamValue();
    }

    /**
     * 获得抢课开始时间
     *
     * @return
     */
    public String getStartTime() {
        return sysParamMapper.selectOne(new QueryWrapper<SysParam>().lambda().eq(SysParam::getParamName, "SELECT_COURSE_START_TIME")).getParamValue();
    }

    /**
     * 系统参数列表
     *
     * @return
     */
    public List<SysParam> selectAll() {
        return sysParamMapper.selectList(new QueryWrapper<>());
    }
}
